package cn.oa.dao.impl;

import cn.oa.dao.BaseDao;
import cn.oa.dao.PositionDao;
import cn.oa.entity.Position;
import cn.oa.util.DatabaseUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class PositionDaoImpl extends BaseDao implements PositionDao {
    public PositionDaoImpl(Connection conn) {
        super(conn);
    }
    @Override
    public List<Position> getAllPositions() throws SQLException {
        List<Position> list = new ArrayList<Position>();
        ResultSet rs = null;
        String sql = "select * from position";
        try{
            rs = this.executeQuery(sql);
            while(rs.next()){
                Position position = new Position();
                position.setId(rs.getInt("id"));
                position.setPosName(rs.getString("posName"));
                list.add(position);
            }
        }catch(SQLException e){
            e.printStackTrace();
        }finally {
            DatabaseUtil.closeAll(null, null, rs);
        }
        return list;
    }
}
